﻿Imports System.Web

Namespace AboutDNN.DNNMVC

#Region "IResponse"

    Public Interface IResponse
        Sub Clear()
        Sub Write(ByVal data As String)
        Property StatusCode() As Integer
        Property StatusDescription() As String
        Sub [End]()
        Property Expires() As Integer
        Sub Cache_SetNoServerCaching()
        Sub Cache_SetNoStore()
        Sub AppendHeader(ByVal header As String, ByVal value As String)
        Property ContentType() As String
        Sub Redirect(ByVal url As String)
        Sub Redirect(ByVal url As String, ByVal endResponse As Boolean)
        Property EndCalled() As Boolean
    End Interface

#End Region



#Region "ASPResponse"

    Class ASPResponse
        Implements IResponse

        Private _response As HttpResponse = HttpContext.Current.Response

        Public Sub AppendHeader(ByVal header As String, ByVal value As String) Implements IResponse.AppendHeader
            _response.AppendHeader(header, value)
        End Sub

        Public Sub Cache_SetNoServerCaching() Implements IResponse.Cache_SetNoServerCaching
            _response.Cache.SetNoServerCaching()
        End Sub

        Public Sub Cache_SetNoStore() Implements IResponse.Cache_SetNoStore
            _response.Cache.SetNoStore()
        End Sub

        Public Sub Clear() Implements IResponse.Clear
            _response.Clear()
        End Sub

        Public Property ContentType() As String Implements IResponse.ContentType
            Get
                Return _response.ContentType
            End Get
            Private Set(ByVal value As String)
                _response.ContentType = value
            End Set
        End Property

        Public Sub [End]() Implements IResponse.End
            _endCalled = True
            _response.End()
        End Sub

        Public Property Expires() As Integer Implements IResponse.Expires
            Get
                Return _response.Expires
            End Get
            Private Set(ByVal value As Integer)
                _response.Expires = value
            End Set
        End Property

        Public Property StatusCode() As Integer Implements IResponse.StatusCode
            Get
                Return _response.StatusCode
            End Get
            Private Set(ByVal value As Integer)
                _response.StatusCode = value
            End Set
        End Property

        Public Property StatusDescription() As String Implements IResponse.StatusDescription
            Get
                Return _response.StatusDescription
            End Get
            Private Set(ByVal value As String)
                _response.StatusDescription = value
            End Set
        End Property

        Public Sub Write(ByVal data As String) Implements IResponse.Write
            _response.Write(data)
        End Sub

        Private _endCalled As Boolean
        Public Property EndCalled() As Boolean Implements IResponse.EndCalled
            Get
                Return _endCalled
            End Get
            Set(ByVal value As Boolean)
                _endCalled = value
            End Set
        End Property

        Public Sub Redirect(ByVal url As String) Implements IResponse.Redirect
            Redirect(url, True)
        End Sub

        Public Sub Redirect(ByVal url As String, ByVal endResponse As Boolean) Implements IResponse.Redirect
            _response.Redirect(url, endResponse)
        End Sub
    End Class

#End Region

End Namespace
